package com.xinzhidi.web.netty.controller;

import com.xinzhidi.common.annotation.Log;
import com.xinzhidi.common.core.controller.BaseController;
import com.xinzhidi.common.core.domain.AjaxResult;
import com.xinzhidi.common.core.domain.R;
import com.xinzhidi.common.core.page.TableDataInfo;
import com.xinzhidi.common.enums.BusinessType;
import com.xinzhidi.common.utils.poi.ExcelUtil;
import com.xinzhidi.web.netty.entity.dto.AgreementHeatAddDto;
import com.xinzhidi.web.netty.entity.dto.AgreementHeatListDto;
import com.xinzhidi.web.netty.entity.dto.AgreementHeatUpdDto;
import com.xinzhidi.web.netty.entity.vo.AgreementHeatInfoVo;
import com.xinzhidi.web.netty.entity.vo.AgreementHeatListVo;
import com.xinzhidi.web.netty.service.AgreementHeatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 户用、单元热量协议-（实时数据）Controller
 *
 * @author cx
 * @date 2023-06-17
 */
@RestController
@Api(tags = "户用、单元热量协议-（实时数据）")
@RequestMapping("/agreementHeat")
public class AgreementHeatController extends BaseController {

    @Autowired
    private AgreementHeatService agreementHeatService;

    @ApiOperation("查询户用、单元热量协议-（实时数据）列表")
    @PreAuthorize("@ss.hasPermi('agreementHeat:agreementHeat:list')")
    @PostMapping("/listAgreementHeat")
    public TableDataInfo<AgreementHeatListVo> listAgreementHeat(@Validated @RequestBody AgreementHeatListDto dto) {
        startPagePost(dto);
        return agreementHeatService.selectAgreementHeatList(dto);
    }

    @ApiOperation("导出户用、单元热量协议-（实时数据）列表")
    @PreAuthorize("@ss.hasPermi('agreementHeat:agreementHeat:export')")
    @Log(title = "户用、单元热量协议-（实时数据）", businessType = BusinessType.EXPORT)
    @PostMapping("/exportAgreementHeat")
    public void exportAgreementHeat(HttpServletResponse response, AgreementHeatListDto dto) {
        TableDataInfo<AgreementHeatListVo> list = agreementHeatService.selectAgreementHeatList(dto);
        ExcelUtil<AgreementHeatListVo> util = new ExcelUtil<AgreementHeatListVo>(AgreementHeatListVo.class);
        util.exportExcel(response, list.getRows(), "户用、单元热量协议-（实时数据）数据");
    }

    @ApiOperation("获取户用、单元热量协议-（实时数据）详细信息")
    @PreAuthorize("@ss.hasPermi('agreementHeat:agreementHeat:query')")
    @GetMapping(value = "/getAgreementHeatById")
    public R<AgreementHeatInfoVo> getAgreementHeatById(@RequestParam("id") Long id) {
        return R.ok(agreementHeatService.selectAgreementHeatById(id));
    }

    @ApiOperation("新增户用、单元热量协议-（实时数据）")
    @PreAuthorize("@ss.hasPermi('agreementHeat:agreementHeat:add')")
    @Log(title = "户用、单元热量协议-（实时数据）", businessType = BusinessType.INSERT)
    @PostMapping("addAgreementHeat")
    public AjaxResult addAgreementHeat(@Validated @RequestBody AgreementHeatAddDto dto) {
        return toAjax(agreementHeatService.insertAgreementHeat(dto));
    }

    @ApiOperation("修改户用、单元热量协议-（实时数据）")
    @PreAuthorize("@ss.hasPermi('agreementHeat:agreementHeat:edit')")
    @Log(title = "户用、单元热量协议-（实时数据）", businessType = BusinessType.UPDATE)
    @PostMapping("editAgreementHeat")
    public AjaxResult editAgreementHeat(@Validated @RequestBody AgreementHeatUpdDto dto) {
        return toAjax(agreementHeatService.updateAgreementHeat(dto));
    }

    @ApiOperation("删除户用、单元热量协议-（实时数据）")
    @PreAuthorize("@ss.hasPermi('agreementHeat:agreementHeat:remove')")
    @Log(title = "户用、单元热量协议-（实时数据）", businessType = BusinessType.DELETE)
    @DeleteMapping("/delAgreementHeat")
    public AjaxResult delAgreementHeat(@RequestParam Long[] ids) {
        return toAjax(agreementHeatService.deleteAgreementHeatByIds(ids));
    }

    @ApiOperation("户用热量表-【热量表时间设置】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "time", value = "时间:格式（YY MM DD hh mm ss）", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/writeHouseholdTime")
    public AjaxResult writeHouseholdTime(Long dtuId, String address, String time) {
        return toAjax(agreementHeatService.writeHouseholdTime(dtuId, address , time));
    }

    @ApiOperation("户用热量表-【读地址】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class)
    })
    @GetMapping("/readHouseholdHeatAddress")
    public AjaxResult readHouseholdHeatAddress(Long dtuId) {
        return toAjax(agreementHeatService.readHouseholdHeatAddress(dtuId));
    }

    @ApiOperation("户用热量表-【设置地址】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "oldAddress", value = "原地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "newAddress", value = "现地址", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/writeHouseholdHeatAddress")
    public AjaxResult writeHouseholdHeatAddress(Long dtuId, String oldAddress, String newAddress) {
        return toAjax(agreementHeatService.writeHouseholdHeatAddress(dtuId, oldAddress, newAddress));
    }

    @ApiOperation("户用热量表-【阀门强开】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "value", value = "值", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/openValve")
    public AjaxResult openValve(Long dtuId, String address, String value) {
        return toAjax(agreementHeatService.openValve(dtuId, address , value));
    }

    @ApiOperation("户用热量表-【阀门强关】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "value", value = "值", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/closeValve")
    public AjaxResult closeValve(Long dtuId, String address, String value) {
        return toAjax(agreementHeatService.closeValve(dtuId, address , value));
    }

    @ApiOperation("单元热量表-【读地址】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class)
    })
    @GetMapping("/readUnitHeatAddress")
    public AjaxResult readUnitHeatAddress(Long dtuId) {
        return toAjax(agreementHeatService.readUnitHeatAddress(dtuId));
    }

    @ApiOperation("单元热量表-【写 设 备 地 址】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "oldAddress", value = "原地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "newAddress", value = "现地址", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/writeUnitHeatAddress")
    public AjaxResult writeUnitHeatAddress(Long dtuId, String oldAddress, String newAddress) {
        return toAjax(agreementHeatService.writeUnitHeatAddress(dtuId, oldAddress, newAddress));
    }

    @ApiOperation("单元热量表-【热量表时间设置】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "time", value = "时间:格式（YY MM DD hh mm ss）", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/writeUnitTime")
    public AjaxResult writeUnitTime(Long dtuId, String address, String time) {
        return toAjax(agreementHeatService.writeUnitTime(dtuId, address , time));
    }


    @ApiOperation("单元热量表-【阀门强开】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "value", value = "值", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/unitOpenValve")
    public AjaxResult unitOpenValve(Long dtuId, String address, String value) {
        return toAjax(agreementHeatService.unitOpenValve(dtuId, address , value));
    }

    @ApiOperation("单元热量表-【阀门强关】指令下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dtuId", value = "dtuId", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "address", value = "设备地址", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "value", value = "值", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("/UnitCloseValve")
    public AjaxResult UnitCloseValve(Long dtuId, String address, String value) {
        return toAjax(agreementHeatService.UnitCloseValve(dtuId, address , value));
    }

}
